package kim.artemis.rpc.core.common.enums;

import kim.artemis.rpc.core.loadbalance.ArtemisRpcLoadBalance;
import kim.artemis.rpc.core.loadbalance.ArtemisRpcLoadBalancePolling;
import kim.artemis.rpc.core.loadbalance.ArtemisRpcLoadBalanceRandom;
import lombok.Getter;

/**
 * 负载均衡路由枚举
 * @author Wq.
 */
public enum LoadBalanceEnum {

    // 轮询
    POLLING(new ArtemisRpcLoadBalancePolling()),
    // 随机
    RANDOM(new ArtemisRpcLoadBalanceRandom());

    @Getter
    public final ArtemisRpcLoadBalance loadBalance;

    LoadBalanceEnum(ArtemisRpcLoadBalance loadBalance) {
        this.loadBalance = loadBalance;
    }

    /**
     * 匹配路由
     * @param name
     * @param defaultRouter
     * @return
     */
    public static LoadBalanceEnum match(String name, LoadBalanceEnum defaultRouter) {
        for (LoadBalanceEnum item : LoadBalanceEnum.values()) {
            if (name.equals(item)) {
                return item;
            }
        }
        return defaultRouter;
    }
}
